package lu.uni.adtool.ui;

import java.awt.Component;
import java.awt.Insets;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolBar;

import lu.uni.adtool.ui.texts.ToolTipTexts;

/**
 * The toolbar used in ADTool application.
 * 
 * @author Piot Kordy
 * @version 
 */
public class ADToolBar extends JToolBar
{
  private static final long serialVersionUID = 883897992310721L;

  /**
   * The default constructor.
   * 
   */
  public ADToolBar()
  {
    super();
  }
   ToolBarButton add(AbstractAction a){
     final Insets margins = new Insets(0, 0, 0, 0);
     ToolBarButton button = new ToolBarButton(super.add(a));
     button.setMargin(margins);
     return button;
   }
  /**
   * Turn off or on the labels for the buttons.
   * 
   * @param labelsAreEnabled if true then the labels are shown.
   */
  public final void setTextLabels(final boolean labelsAreEnabled)
  {
    Component c;
    int i = 0;
    while ((c = getComponentAtIndex(i++)) != null) {
      ToolBarButton button;
      try{
        button = (ToolBarButton) c;
      }
      catch(ClassCastException e){
        continue;
      }
      if (labelsAreEnabled){
        button.setText(button.getToolTipText());
      }
      else {
        button.setText(null);
      }
    }
  }
}
